package me.zhengjie.mi.neww;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import com.alibaba.fastjson.JSONObject;
import io.minio.*;
import io.minio.errors.MinioException;
import io.minio.messages.Bucket;
import me.zhengjie.utils.CalculateAge;
import me.zhengjie.utils.DistributeSbgs;

import java.io.ByteArrayInputStream;
import java.io.FileInputStream;
import java.util.Base64;
import java.util.List;

public class SafetyTest {

    public static void main(String args[]) throws Exception {
/*

        MinioClient minioClient =

            new MinioClient("http://120.92.159.128:9001", "ddappuser", "dd1234@1");
*/

        MinioClient minioClient = MinioClient.builder()
                .endpoint("http://192.168.10.250:9000")
                .credentials("admin", "123456780")
                .build();

        String date = DateUtil.format(DateUtil.date(), DatePattern.NORM_DATE_PATTERN);

        String bucket = "zhsystem.20220712";

        if(!minioClient.bucketExists(BucketExistsArgs.builder().bucket(bucket).build())) {
            minioClient.makeBucket(MakeBucketArgs.builder().bucket(bucket).build());
        }
      //String config = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\",\"s3:ListBucketMultipartUploads\"],\"Resource\":[\"arn:aws:s3:::"+bucket+"\"]},{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":[\"*\"]},\"Action\":[\"s3:GetObject\",\"s3:ListMultipartUploadParts\",\"s3:PutObject\",\"s3:AbortMultipartUpload\",\"s3:DeleteObject\"],\"Resource\":[\"arn:aws:s3:::"+bucket+"/*\"]}]}";
        String config = "{\"Version\":\"2012-10-17\",\"Statement\":[{\"Action\":[\"s3:GetBucketLocation\",\"s3:ListBucket\"],\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:s3:::"+bucket+"\"},{\"Action\":\"s3:GetObject\",\"Effect\":\"Allow\",\"Principal\":\"*\",\"Resource\":\"arn:aws:s3:::"+bucket+"/*\"}]}";
     //   minioClient.setBucketPolicy(bucket, );
        minioClient.setBucketPolicy(SetBucketPolicyArgs.builder().bucket(bucket).config(config).build());
        System.out.println(minioClient.getBucketPolicy(GetBucketPolicyArgs.builder().bucket(bucket).build()));


        FileInputStream fileInputStream = new FileInputStream("F:\\1233334.jpg");

        minioClient.putObject(bucket, "1233334.jpg", "F:\\\\1233334.jpg", new PutObjectOptions(fileInputStream.available(), -1));
        fileInputStream.close();

     //   String url = minioClient.presignedGetObject("mypic", "my2object.png", 60 * 60 * 24);
     //   System.out.println(url);
    //    String url = minioClient.presignedGetObject("mypic", "src=http___i1.hdslb.com_bfs_archive_e6ab6c081835d73a39b68cf787e23e9968ce1ad4.jpg&refer=http___i1.hdslb.jpg", 60 * 60 * 24);
    //    System.out.println(url);
    }
}
